import React from 'react';
import { Card } from 'antd';
import { isEditorENV } from '@inbiz/utils';
import { routerPrefix } from 'InbizConfig';
import Title from './title';
import Source from './source';
import { NewsItemProps } from '../../index';
import ImgLoader from './imgLoader';

const { Meta } = Card;

const SummaryItem: React.FC<NewsItemProps> = (props) => {
  const { ImgUrl, ContentUrl, detail, ID, newsKey,ContentCategory} = props;

  const prefix = 'inbiz-News-card';
  const jumpToDetail = () => {
    const { origin, pathname, search } = window.location;
    // 设计器环境
    if (isEditorENV()) {
      return;
    }
    if (!!ContentUrl) {
      window.open(ContentUrl);
      return;
    }
    if (!detail) return;
    const [name] = detail.split(',');
    window.open(
      `${origin}${pathname}${search}#${routerPrefix}${name}?newsId=${ID}&cateId=${ContentCategory}`,
    );
  };

  return (
    <Card
      hoverable
      cover={
        <ImgLoader onClick={jumpToDetail} className={`${prefix}-img`} src={ImgUrl} key={ImgUrl} />
      }
    >
      <Meta
        title={<Title {...props} tagType="card" />}
        description={<Source type={3} {...props} />}
      />
    </Card>
  );
};

export default SummaryItem;
